/**
 * Created by Dalyn on 2017/4/13.
 */
import React from "react";
import Relay from "react-relay";
import Confirm from '../../../common/Confirm'
import Select from '../../../common/Select'
import InputBox from '../../../common/InputBox'
import SignOrderMutation from "./mutation/SignOrderMutation"
import "./css/OrderDetailPartB.css"
import "./css/OrderDetail.css"
import Reactkey from "../../../util/ReactKey"
import SignModal from "./SignModal";
import { message} from 'antd';
export default class OrderdetailPartA extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            serviceType:'',
            order:[],
        };
        this.order = "";
        this.partBId = "";
        this.isSign = false;
        /*乙方企业*/
        // this.addpartb_arr = [
        //     {partbname:"山东1",status:"1"},
        //     {partbname:"山东2",status:"2"},
        // ];
    }
    componentWillMount(){
        this.order = this.props.order;
        this.setState({
            orderstatus:this.order.status,
            order:this.props.order
        });
        let orderOperates = this.order.orderOperates?this.order.orderOperates:[];
    }
    /*选择已接单的乙方企业*/
    choosepartB(item){
        this.isSign = true;
        this.partBId = item.toId;
    }

    /*乙方企业列表*/
    addpartb(){
        let addpartb_arr = this.order.orderOperates?this.order.orderOperates:[];
        return addpartb_arr.map((item,index)=>{
            // console.log(item.status);
            if(item.status >= "2"){
                return(
                    <div className="order_detail_gms_partb_item">
                        <label className="order_detail_gms_partb_label" htmlFor="">
                            <input className="order_detail_partb_radio" type="radio" name="sex" value={"partb"+index} onChange={this.choosepartB.bind(this,item)} />{item.toUserName}
                        </label>
                        <span htmlFor="" className="order_detail_gms_partb_span">已接单</span>
                    </div>
                )
            }else {
                return(
                    <div className="order_detail_gms_partb_item">
                        <label className="order_detail_gms_partb_label" htmlFor="">
                            <input className="order_detail_partb_radio" type="radio" name="sex" value={"partb"+index} disabled/>{item.toUserName}
                        </label>

                        <span htmlFor="" className="order_detail_gms_partb_span">未接单</span>
                    </div>
                )
            }

        })
    }
    /*点击签订*/
    signOrder(){
        if(this.isSign){
        this.refs.signmodal.setState({
            visible:true
        });
        }else{
            message.info('请选择企业');
        }


    }

    SingOrderCallBack(tnum,instructions){
            Relay.Store.commitUpdate(
                new SignOrderMutation({
                    orderId: this.order.oid,
                    enId: this.partBId,
                    signedContract: tnum,
                    signedContractUrl1: instructions[0]||'',
                    signedContractUrl2: instructions[1]||'',
                    signedContractUrl3: instructions[2]||'',
                    signedContractUrl4: instructions[3]||'',
                    signedContractUrl5: instructions[4]||'',
                }),
                {
                    onFailure: () => {
                        // console('成衣订单详情请求失败');
                    },
                    onSuccess: (response) => {
                        let errorCode = response.signOrder.signOrder.errorCode;
                        if(errorCode=='0'){
                            let order = response.signOrder.signOrder.order;
                            this.order = order;
                            this.setState({
                                orderstatus:order.status,
                            });
                            this.refs.signmodal.setState({
                                visible:false
                            });
                            this.props.Orderdetail()
                        }
                    }
                }
            )

    }


    render() {
        return (
            <div>
                {/*添加乙方*/}
                {
                  // <div className="order_detail_addpartb" style={this.state.orderstatus <= 2 ?{display:"block"}:{display:"none"}} >
                  //     <p className="order_detail_addpart_p" >已发送乙方</p>
                  //     <div className="order_detail_gms_partb">
                  //         {
                  //             this.addpartb()
                  //         }
                  //         <Confirm style={{width:80,height:28,fontSize:"14px",color:"#fff",marginLeft:"500px",backgroundColor:"#1fbba6"}} tcontext="签订" touch={this.signOrder.bind(this)}/>
                  //     </div>
                  // </div>
                }
                {/*客户信息*/}
                {/*<div className="order_detail_customer" style={this.props.serviceType == "6" ? {display:"block"}:{display:"none"}} >*/}
                    {/*<p className="order_detail_addpart_orderp" style={{borderBottom: '1px solid #f0f0f0'}}>客户信息</p>*/}
                    {/*<div className="order_detail_customer_info clear">*/}
                        {/*<div className="order_detail_customer_infoleft">*/}
                            {/*<p className="order_detail_customer_infop">*/}
                                {/*<span className="order_detail_customer_infospan1">客户：</span>*/}
                                {/*<span className="order_detail_customer_infospan2">{this.state.order.traderName == null || this.state.order.traderName == 'null' ? '' : this.state.order.traderName}</span>*/}
                            {/*</p>*/}

                            {/*<p className="order_detail_customer_infop">*/}
                                {/*<span className="order_detail_customer_infospan1">联系人：</span>*/}
                                {/*<span className="order_detail_customer_infospan2">{this.state.order.traderUser == null || this.state.order.traderUser == 'null' ? '' : this.state.order.traderUser}</span>*/}
                            {/*</p>*/}
                            {/*<p className="order_detail_customer_infop">*/}
                                {/*<span className="order_detail_customer_infospan1">合同编号：</span>*/}
                                {/*<span className="order_detail_customer_infospan2">{this.state.order.traderId == null || this.state.order.traderId == 'null' ? '' : this.state.order.traderId}</span>*/}
                            {/*</p>*/}
                            {
                              /*
                              <p className="order_detail_customer_infop">
                                  <span className="order_detail_customer_infospan1">联系电话：</span>
                                  <span className="order_detail_customer_infospan2">{this.state.order.partAPhone}</span>
                              </p>
                              */
                            }
                        {/*</div>*/}
                        {
                          /*
                          <div className="order_detail_customer_inforight">
                              <p className="order_detail_customer_infop">
                                  <span className="order_detail_customer_infospan1">地址：</span>
                                  <span className="order_detail_customer_infospan2">{this.state.order.partAAddress}</span>
                              </p>

                              <p className="order_detail_customer_infop">
                                  <span className="order_detail_customer_infospan1">合同编号：</span>
                                  <span className="order_detail_customer_infospan2">{this.state.order.contractId}</span>
                              </p>

                              <p className="order_detail_customer_infop">
                                  <span className="order_detail_customer_infospan1">合同附件：</span>
                                  <span className="order_detail_customer_infospan2">{this.state.order.traderUrl1}{this.state.order.traderUrl2}{this.state.order.traderUrl3}{this.state.order.traderUrl4}{this.state.order.traderUrl5}</span>
                              </p>
                          </div>
                          */
                        }
                    {/*</div>*/}
                {/*</div>*/}
                {/*订单编号*/}
                <div className="order_detail_orderId">
                    <p className="order_detail_addpart_orderp"  style={{borderBottom: '1px solid #f0f0f0'}}>订单编号：{this.state.order.oid == null || this.state.order.oid == 'null' ? '' : this.state.order.oid}</p>
                    <div className="order_detail_customer_info clear">
                        <div className="order_detail_customer_infoleft">
                            <p className="order_detail_customer_infop">
                                <span className="order_detail_customer_infospan1" title={this.state.order.partAName || ''}>甲方：</span>
                                <span className="order_detail_customer_infospan2">{this.state.order.partAName == null || this.state.order.partAName == 'null' ? '' : this.state.order.partAName}</span>
                            </p>

                            <p className="order_detail_customer_infop">
                                <span className="order_detail_customer_infospan1">地址：</span>
                                <span className="order_detail_customer_infospan2">{this.state.order.partAAddress == null || this.state.order.partAAddress == 'null' ? '' : this.state.order.partAAddress}</span>
                            </p>

                            <p className="order_detail_customer_infop">
                                <span className="order_detail_customer_infospan1">联系人：</span>
                                <span className="order_detail_customer_infospan2" style={{width: 'auto'}}>{this.state.order.partAUserName == null || this.state.order.partAUserName == 'null' ? '' : this.state.order.partAUserName}</span>
                                <span className="order_detail_customer_infospan2" style={{width: 'auto'}}>{this.state.order.partAPhone == null || this.state.order.partAPhone == 'null' ? '' : this.state.order.partAPhone}</span>
                            </p>
                        </div>
                        <div className="order_detail_customer_inforight">
                            <p className="order_detail_customer_infop">
                                <span className="order_detail_customer_infospan1">乙方：</span>
                                <span className="order_detail_customer_infospan2" title={this.state.order.partBName || ''}>{this.state.order.partBName == null || this.state.order.partBName == 'null' ? '' : this.state.order.partBName}</span>
                            </p>

                            <p className="order_detail_customer_infop">
                                <span className="order_detail_customer_infospan1">地址：</span>
                                <span className="order_detail_customer_infospan2">{this.state.order.partBAddress == null || this.state.order.partBAddress == 'null' ? '' : this.state.order.partBAddress}</span>
                            </p>

                            <p className="order_detail_customer_infop">
                                <span className="order_detail_customer_infospan1">联系人：</span>
                                <span className="order_detail_customer_infospan2" style={{width: 'auto'}}>{this.state.order.partBUserName == null || this.state.order.partBUserName == 'null' ? '' : this.state.order.partBUserName}</span>
                                <span className="order_detail_customer_infospan2" style={{width: 'auto'}}>{this.state.order.partBPhone == null || this.state.order.partBPhone == 'null' ? '' : this.state.order.partBPhone}</span>
                            </p>
                        </div>
                    </div>
                </div>
                <SignModal ref={'signmodal'} SingOrderCallBack = {this.SingOrderCallBack.bind(this)}/>
            </div>
        );
    }
}
